package com.zfcer.chapter03;

/**
 * @Classname Queue
 * @Description 队列实现
 * @Created by zfcer
 * @Date 2022/4/19 14:14
 */
public class Queue {
    private final static int SIZE = 100;
    private int[] arr;
    private int top, rear;

    public void init(){
        arr = new int[SIZE];
        top = rear = 0;
    }

    public boolean offer(int val){
        if(rear > SIZE) return false;
        arr[rear++] = val;
        return true;
    }

    public int poll(){
        if(top >= rear) return 0;
        return arr[top++];
    }

    public int peek(){
        if(top >= rear) return 0;
        return arr[top];
    }

}
